//
//  ViewController.m
//  IDLFaceSDKDemoOC
//
//  Created by Tong,Shasha on 2017/5/15.
//  Copyright © 2017年 Baidu. All rights reserved.
//
#import "ViewController.h"
#import "BDFaceAgreementViewController.h"
#import "BDFaceLogoView.h"
#import <objc/runtime.h>
#import "JSToastDialogs.h"
#import "BDFacePoorNetworkController.h"
#import "BDFaceVerificationFailController.h"
#import "BDUIConstant.h"
#import "BDFaceVerificationConstant.h"
#import "BDIDInfoAutoCollectController.h"
#import "BDIDInfoCollectController.h"
#import "BDSettingViewController.h"
#import "ViewController+MainSteps.h"
#import "ViewController+LiveCheck.h"

#import "FaceParameterConfig.h"
#import "BDFaceAdjustParamsTool.h"

#define ScreenRect [UIScreen mainScreen].bounds
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

@interface ViewController ()
@property (strong, nonatomic) UIButton *startBtn;
@property (strong, nonatomic) UIImage *idCardImage;
@property (weak, nonatomic) UIViewController *vc;
@property (strong, nonatomic) UIImageView *warningView;
@property (strong, nonatomic) UILabel *waringLabel;
@property (strong, nonatomic) UIButton *checkAgreeButton;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColorFromRGB(0xF0F1F2);
    UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), KScaleX(240))];
    [self.view addSubview:bgView];
    bgView.image = [UIImage imageNamed:@"image_guide"];
    
    // 设置按钮
        UIButton *settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        settingBtn.frame = CGRectMake((ScreenWidth-28-32), KScaleY(42.7), 44, 44);
        [settingBtn setImage:[UIImage imageNamed:@"icon_titlebar_setting_new"] forState:UIControlStateNormal];
        [settingBtn addTarget:self action:@selector(settingAction) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:settingBtn];
    
    // 底部logo部分
    UIImageView *logoImageView = [[UIImageView alloc] init];
    logoImageView.frame = CGRectMake(0, CGRectGetMaxY(self.view.frame) - 221, ScreenWidth, 221);
    logoImageView.image = [UIImage imageNamed:@"image_guide_bottom"];
    [self.view addSubview:logoImageView];
    
    // 欢迎使用的label
    UILabel *welcome = [[UILabel alloc] init];
    welcome.frame = CGRectMake(KScaleX(57), KScaleY(96), ScreenWidth-KScaleX(68*2), 30);
    welcome.text = @"为保证您的信息安全";
    welcome.textAlignment = NSTextAlignmentLeft;
    welcome.font =  [UIFont fontWithName:@"PingFangSC-Light" size:20];
    welcome.textColor = UIColorFromRGB(0x171D24);
    
    [self.view addSubview:welcome];
    
    // 欢迎使用的下一行
    UILabel *welcomeNext = [[UILabel alloc] init];
    welcomeNext.frame = CGRectMake(KScaleX(57), welcome.frame.origin.y + 35, 261, 40);
    welcomeNext.text = @"请进行人脸识别认证";
    welcomeNext.textAlignment = NSTextAlignmentLeft;
    welcomeNext.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:28];
    welcomeNext.textColor = UIColorFromRGB(0x171D24);
    [self.view addSubview:welcomeNext];
    
    // 确保本人操作的提示和图片
    UIImageView *lightImage = [[UIImageView alloc] init];
    lightImage.frame =  CGRectMake(57, 232*ScreenHeight/667, 44, 44);
    lightImage.image = [UIImage imageNamed:@"home_image1"];
    [self.view addSubview:lightImage];
    UILabel *adjustLight = [[UILabel alloc] init];
    adjustLight.frame =  CGRectMake(121, 232*ScreenHeight/667, 108, 18);
    adjustLight.text = @"确保本人操作";
    adjustLight.font = [UIFont fontWithName:@"PingFangSC-Medium" size:18];
    adjustLight.textColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:1 / 1.0];
    [self.view addSubview:adjustLight];
    UILabel *adjustLight2 = [[UILabel alloc] init];
    adjustLight2.frame =  CGRectMake(121, adjustLight.frame.origin.y + 28, 168, 14);
    adjustLight2.text = @"非本人操作将无法通过认证";
    adjustLight2.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    adjustLight2.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1 / 1.0];
    [self.view addSubview:adjustLight2];
    
    // 识别光线适中图片和提示
    UIImageView *angleImage = [[UIImageView alloc] init];
    angleImage.frame = CGRectMake(57, 307*ScreenHeight/667, 44, 44);
    angleImage.image = [UIImage imageNamed:@"home_image2"];
    [self.view addSubview:angleImage];
    UILabel *focesText = [[UILabel alloc] init];
    focesText.frame = CGRectMake(121, 307*ScreenHeight/667, 108, 18);
    focesText.text = @"识别光线适中";
    focesText.font = [UIFont fontWithName:@"PingFangSC-Medium" size:18];
    focesText.textColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:1 / 1.0];
    [self.view addSubview:focesText];
    UILabel *focesTextNext = [[UILabel alloc] init];
    focesTextNext.frame = CGRectMake(121, focesText.frame.origin.y + 28, 168, 14);
    focesTextNext.text = @"请保证光线不要过暗或过亮";
    focesTextNext.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    focesTextNext.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1 / 1.0];
    [self.view addSubview:focesTextNext];
    
    // 正面对准手机的图片和提示
    UIImageView *maskImage = [[UIImageView alloc] init];
    maskImage.frame = CGRectMake(57, 382*ScreenHeight/667, 44, 44);
    maskImage.image = [UIImage imageNamed:@"home_image3"];
    [self.view addSubview:maskImage];
    UILabel *maskText = [[UILabel alloc] init];
    maskText.frame = CGRectMake(121, 382*ScreenHeight/667, 108, 18);
    maskText.text = @"正面对准手机";
    maskText.font = [UIFont fontWithName:@"PingFangSC-Medium" size:18];
    maskText.textColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:1 / 1.0];
    [self.view addSubview:maskText];
    UILabel *maskTextNext = [[UILabel alloc] init];
    maskTextNext.frame = CGRectMake(121, maskText.frame.origin.y + 28, 168, 14);
    maskTextNext.text = @"保持您的脸出现在取景框内";
    maskTextNext.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    maskTextNext.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1 / 1.0];
    [self.view addSubview:maskTextNext];
    
    // 初始化默认业务场景为实名认证方式，配置设置页面业务默认设置AirInterface为1
    NSInteger type = [[NSUserDefaults standardUserDefaults] integerForKey:@"AirInterface"];
    if (type == 0) {
        [[NSUserDefaults standardUserDefaults] setInteger: 1 forKey:@"AirInterface"];
    }
    
    // 开始采集的Button
    self.startBtn  = [[UIButton alloc] init];
    self.startBtn.frame = CGRectMake(KScaleX(48), ScreenHeight-52-KScaleY(104), ScreenWidth-KScaleX(48*2), 52);
    [self.startBtn setBackgroundColor:[UIColor colorWithRed:0 / 255.0 green:128 / 255.0 blue:255 / 255.0 alpha:1 / 1.0]];
    self.startBtn.layer.cornerRadius = 52/2;
    self.startBtn.layer.masksToBounds = YES;
    [self.startBtn setTitle:@"开始身份认证" forState:UIControlStateNormal];
    self.startBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    [self.startBtn setBackgroundImage:[self createImageWithColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.29]] forState:UIControlStateHighlighted];
    [self.view addSubview:self.startBtn];
    // 实名认证采集按钮 --当前页面搜索startGatherAction查看示例代码
    [self.startBtn addTarget:self action:@selector(startGatherAction:) forControlEvents:UIControlEventTouchUpInside];
    CGFloat remdinderHeight = 13.0f;
    
    // 在线图片活体接口按钮
//    UIButton *onlinePicBtn = [[UIButton alloc] init];
//    onlinePicBtn.frame = CGRectMake(KScaleX(48), ScreenHeight-52-KScaleY(104)-64,ScreenWidth-KScaleX(48*2), 52);
//    [onlinePicBtn setBackgroundColor:[UIColor colorWithRed:0 / 255.0 green:128 / 255.0 blue:255 / 255.0 alpha:1 / 1.0]];
//    onlinePicBtn.layer.cornerRadius = 52/2;
//    onlinePicBtn.layer.masksToBounds = YES;
//    [onlinePicBtn setTitle:@"开始活体检测" forState:UIControlStateNormal];
//    onlinePicBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
//    [onlinePicBtn setBackgroundImage:[self createImageWithColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.29]] forState:UIControlStateHighlighted];
//    [self.view addSubview: onlinePicBtn];
//    [onlinePicBtn addTarget:self action:@selector(startOnlinePicAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 对比接口按钮
//    UIButton *onlineMatchBtn = [[UIButton alloc] init];
//    onlineMatchBtn.frame = CGRectMake(KScaleX(48), ScreenHeight-52-KScaleY(104)-64-64,ScreenWidth-KScaleX(48*2), 52);
//    [onlineMatchBtn setBackgroundColor:[UIColor colorWithRed:0 / 255.0 green:128 / 255.0 blue:255 / 255.0 alpha:1 / 1.0]];
//    onlineMatchBtn.layer.cornerRadius = 52/2;
//    onlineMatchBtn.layer.masksToBounds = YES;
//    [onlineMatchBtn setTitle:@"开始对比检测" forState:UIControlStateNormal];
//    onlineMatchBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
//    [onlineMatchBtn setBackgroundImage:[self createImageWithColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.29]] forState:UIControlStateHighlighted];
//    [self.view addSubview: onlineMatchBtn];
//    [onlineMatchBtn addTarget:self action:@selector(startMatchOnlinePicAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView * remindView = [[UIView alloc] init];
    remindView.frame = CGRectMake((self.view.frame.size.width-162)/2, ScreenHeight-16-KScaleY(63), ScreenWidth, remdinderHeight);
    // 勾选人脸验证协议的button
    UIButton *checkAgreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    checkAgreeBtn.frame = CGRectMake(-3.0f * remdinderHeight, -1.0f * remdinderHeight+7, 24, 24);
    [checkAgreeBtn setImage:[UIImage imageNamed:@"icon_guide"] forState:UIControlStateNormal];
    [checkAgreeBtn addTarget:self action:@selector(checkAgreeClick:) forControlEvents:UIControlEventTouchUpInside];
    [remindView addSubview:checkAgreeBtn];
    self.checkAgreeButton = checkAgreeBtn;
    
    UILabel *agreeLabel = [[UILabel alloc] init];
    agreeLabel.frame = CGRectMake(-8, 0, 78, remdinderHeight);
    agreeLabel.text = @"阅读并同意";
    agreeLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:remdinderHeight];
    agreeLabel.textColor = KColorFromRGB(0x77787A);
    [remindView addSubview:agreeLabel];
    
    // 人脸验证协议的label，提供了点击响应事件
    UILabel *remindLabel = [[UILabel alloc] init];
    remindLabel.frame = CGRectMake(60, 0, 162, remdinderHeight);
    remindLabel.text = @"《实名认证用户隐私协议》";
    remindLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:remdinderHeight];
    remindLabel.textColor = KColorFromRGB(0x0080FF);
    remindLabel.userInteractionEnabled = YES;
    UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(agreementAction:)];
    [remindLabel addGestureRecognizer:labelTapGestureRecognizer];
    [remindView addSubview:remindLabel];
    [self.view addSubview:remindView];
    
    [self.view bringSubviewToFront:checkAgreeBtn];
    CGRect rect = [remindView convertRect:checkAgreeBtn.frame toView:self.view];
    [checkAgreeBtn removeFromSuperview];
    [self.view addSubview:checkAgreeBtn];
    checkAgreeBtn.frame = rect;
    
    
    // 不正常操作问题
    // 弹窗的view
    self.warningView = [[UIImageView alloc] init];
    self.warningView.frame = CGRectMake((ScreenWidth - 208) / 2, 298, 208, 44);
    self.warningView.image = [UIImage imageNamed:@"icon_notice"];
    // 弹窗的label内容
    self.waringLabel = [[UILabel alloc] init];
    self.waringLabel.frame = CGRectMake((ScreenWidth - 168) / 2, 310, 168, 14);
    self.waringLabel.text = @"请先同意《人脸验证协议》";
    self.waringLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    self.waringLabel.textColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1 / 1.0];
    
    // 设置logo，底部的位置和大小，实例化显示
    BDFaceLogoView* logoView = [[BDFaceLogoView alloc] initWithFrame:CGRectMake(0, (ScreenHeight-15-12), ScreenWidth, 12)];
    [self.view addSubview:logoView];
    
    /*
     初始化人脸SDK 和 OCR身份证识别SDK
     */
    // 可以参考getAccessToken方法提供accesstoken获取
     [self getAccessToken];
    // 默认初始化SDK参数配置+鉴权
    [self initFaceServiceAndInfoCollectService];
}

/**
 选中高亮状态下的按钮颜色
 */
- (UIImage *)createImageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0, 0, 1, 1);  //图片尺寸
    UIGraphicsBeginImageContext(rect.size); //填充画笔
    CGContextRef context = UIGraphicsGetCurrentContext(); //根据所传颜色绘制
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect); //联系显示区域
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext(); // 得到图片信息
    UIGraphicsEndImageContext(); //消除画笔
    return image;
}

- (IBAction)checkAgreeClick:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (sender.selected) {
        [self.checkAgreeButton setImage:[UIImage imageNamed:@"icon_guide_s"] forState:UIControlStateNormal];
    } else {
        [self.checkAgreeButton setImage:[UIImage imageNamed:@"icon_guide"] forState:UIControlStateNormal];
    }
    // 如果再次点击选中button，提示窗口消失
    [self.warningView removeFromSuperview];
    [self.waringLabel removeFromSuperview];
}

- (void)settingAction {
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Setting" bundle:[NSBundle mainBundle]];
    BDSettingViewController *setting = [story instantiateViewControllerWithIdentifier:NSStringFromClass([BDSettingViewController class])];
    [self.navigationController pushViewController:setting animated:YES];
}

#pragma mark - Button Action
/**
 实名认证接口demo层调用示例 -- 需要配合使用getVerifyToeken方法获取VerifyToeken后完成采集流程验证，具体参考集成文档流程实现
 */
- (IBAction)startGatherAction:(UIButton *)sender {
    [BDFaceVerificationConstant sharedInstance].verifyType = BDFaceVerificationIdCardAndImageVerification;
    if (!self.checkAgreeButton.selected){
        [[JSToastDialogs shareInstance] makeToast:@"请先同意《实名认证用户隐私协议》" duration:1.0];
        return;
    }
   
    // 初始化默认业务场景为实名认证方式，配置设置页面业务默认设置AirInterface为1
    NSInteger type = [[NSUserDefaults standardUserDefaults] integerForKey:@"AirInterface"];
    if (type == 1) {
    // 默认设置实名认证 matchSource = 0
        [[NSUserDefaults standardUserDefaults] setValue:@"0" forKey:@"matchSource"];
    } else if (type == 2) {
    // 人脸对比   matchSource = 1
        [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"matchSource"];
    } else if (type == 3) {
        // 人脸对比   matchSource = 2
        [[NSUserDefaults standardUserDefaults] setValue:@"2" forKey:@"matchSource"];
    } else {
        // 默认实名认证方案 matchSource = 0
        [[NSUserDefaults standardUserDefaults] setValue:@"0" forKey:@"matchSource"];
    }
    
    [[NSUserDefaults standardUserDefaults] synchronize];
    _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    //设置指示器的位置和宽高
    _activityIndicator.frame = CGRectMake(0, 0, 100, 100);
    _activityIndicator.center = [UIApplication sharedApplication].keyWindow.center;
    _activityIndicator.backgroundColor = [UIColor colorWithRed:217/255.0 green:223/255.0 blue:230/255.0 alpha:1];
    _activityIndicator.layer.cornerRadius = 8;
    [_activityIndicator startAnimating];
    [[UIApplication sharedApplication].keyWindow addSubview:_activityIndicator];
    // 请求verify_token
    [self getVerifyToeken];
    // 6.3实名认证调用方式
//    [self startCheck];
    // 6.3在线活体
//    [self startLiveCheck];
    [[NSNotificationCenter defaultCenter] observationInfo];
}

/**
 图片活体接口方法demo参考示例
 */
- (IBAction)startOnlinePicAction:(UIButton *)sender {
    [BDFaceVerificationConstant sharedInstance].verifyType = BDFaceVerificationLiveCheck;
    if (!self.checkAgreeButton.selected){
        [[JSToastDialogs shareInstance] makeToast:@"请先同意《人脸验证协议》" duration:1.0];
        return;
    }
    // 在线图片活体调用
    [[NSUserDefaults standardUserDefaults] setValue:@"2" forKey:@"matchSource"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    // 调用服务端下发请求
    _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    //设置指示器的位置和宽高
    _activityIndicator.frame = CGRectMake(0, 0, 100, 100);
    _activityIndicator.center = [UIApplication sharedApplication].keyWindow.center;
    _activityIndicator.backgroundColor = [UIColor colorWithRed:217/255.0 green:223/255.0 blue:230/255.0 alpha:1];
    _activityIndicator.layer.cornerRadius = 8;
    [_activityIndicator startAnimating];
    [[UIApplication sharedApplication].keyWindow addSubview:_activityIndicator];
    // 请求verify_token
    [self getVerifyToeken];
    [[NSNotificationCenter defaultCenter] observationInfo];
}

/**
 图片对比接口方法demo参考示例
 */
- (IBAction)startMatchOnlinePicAction:(UIButton *)sender {
    [BDFaceVerificationConstant sharedInstance].verifyType = [BDFaceVerificationConstant sharedInstance].verifyType = BDFaceVerificationDoubleImagesCompare;
    if (!self.checkAgreeButton.selected){
        [[JSToastDialogs shareInstance] makeToast:@"请先同意《人脸验证协议》" duration:1.0];
        return;
    }
    // 在线图片活体调用
    [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"matchSource"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    //设置指示器加载动画的位置和宽高
        _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    _activityIndicator.frame = CGRectMake(0, 0, 100, 100);
    _activityIndicator.center = [UIApplication sharedApplication].keyWindow.center;
    _activityIndicator.backgroundColor = [UIColor colorWithRed:217/255.0 green:223/255.0 blue:230/255.0 alpha:1];
    _activityIndicator.layer.cornerRadius = 8;
    [_activityIndicator startAnimating];
    [[UIApplication sharedApplication].keyWindow addSubview:_activityIndicator];
     // demo请求verify_token示例逻辑调用 仅供参考
    [self getVerifyToeken];
    [[NSNotificationCenter defaultCenter] observationInfo];
}

- (IBAction)agreementAction:(UILabel *)sender{
    BDFaceAgreementViewController *avc = [[BDFaceAgreementViewController alloc] init];
    [self.navigationController pushViewController:avc animated:YES];
}

/**
 * 注意！！！此处为获取verifyToken的示例代码！！！
 * verifyToken的获取需要放在APP服务端，APP服务端获取之后再下发给客户端使用
 */
- (void)getVerifyToeken {
    __weak typeof(self) this = self;
    // 获取verifytoken接口
    // 开放api url后面拼接的accesstoken需要请求获取避免过期 确保aksk正确
    NSString *BDTokenGetRequestUrl = [NSString stringWithFormat:@"https://aip.baidubce.com/rpc/2.0/brain/solution/faceprint/verifyToken/generate?access_token=%@",self.accessToken];
    // 超时时间设置
    static NSUInteger BDFaceRequestTokenMaxTime = 60;
    NSString *type = [[NSUserDefaults standardUserDefaults] objectForKey:@"matchSource"];
    int sourceType = [type intValue];
    NSDictionary *tokenDic = @{@"plan_id": planID, @"match_source": @(sourceType)};
    
    NSURL *url = [NSURL URLWithString:BDTokenGetRequestUrl];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:BDFaceRequestTokenMaxTime];
    [request setHTTPMethod:@"POST"];
    [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:tokenDic options:NSJSONWritingPrettyPrinted error:nil];
    if (jsonData != nil && [jsonData isKindOfClass:[NSData class]]) {
        [request setHTTPBody:jsonData];
    }
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    configuration.requestCachePolicy = NSURLRequestReloadIgnoringCacheData;
    configuration.timeoutIntervalForRequest = BDFaceRequestTokenMaxTime;
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        if (data) {
            NSMutableDictionary *responseDic = [NSJSONSerialization JSONObjectWithData: data
                                                                               options: NSJSONReadingMutableContainers
                                                                                 error: &error];
            dispatch_async(dispatch_get_main_queue(), ^{
                NSString *tokenString = responseDic[@"result"][@"verify_token"];
                this.verifyToken = tokenString;
                [_activityIndicator stopAnimating];
                // 调用人脸采集相关接口
                // 视频路径返回属性默认
                [BDFaceBaseKitManager sharedInstance].paramsCustomConfigItem.recordAbility = YES;
                [self startCheck];
            });
        } else {
            dispatch_async(dispatch_get_main_queue(), ^{
                [_activityIndicator stopAnimating];
                [BDFaceToastView showToast:[UIApplication sharedApplication].keyWindow text: @"服务异常"];
            });
        }
    }];
    [task resume];
}

@end

